/**
 * fileName:  EfficacyWriter.java
 * author:  Lei
 * Company:  Cloudland Studio
 * Createdate:  2014-6-3 下午9:26:23
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-3          Lei            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.write;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseWrite;
import org.cloudland.commercial.masterdata.store.entity.EfficacyEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.EfficacyDictEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.EfficacyDictMapper;
import org.cloudland.util.Randoms;
import org.springframework.stereotype.Service;

 /**
 * <pre> 
 * TODO 请充分描述该类提供的作用, 或与其他类会有关联的使用。
 * 使用 java.lang.Object#toString(), 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * @ClassName  EfficacyWriter
 * @author  Lei
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
@Service
public class EfficacyWriter implements DatabaseWrite<EfficacyEntity> {
	
	@Resource(name = "efficacyDictMapper")
	private EfficacyDictMapper efficacyMapper;

	/**
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 *   
	 */
	public EfficacyWriter() {
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * @param entity
	 */
	public void save(EfficacyEntity entity) {
		
		String uuid = Randoms.uuid();
		short sort = Short.parseShort(entity.getSort().toString());
		
		entity.setId(uuid);
		EfficacyDictEntity daoEntity = new EfficacyDictEntity(entity.getId(), entity.getName(), entity.getDesc(), sort);
		efficacyMapper.add(daoEntity);
	}
	
	/**
	 * @param entity
	 */
	public void update(EfficacyEntity entity) {
		short sort = Short.parseShort(entity.getSort().toString());
		EfficacyDictEntity daoEntity = new EfficacyDictEntity(entity.getId(), entity.getName(), entity.getDesc(), sort);
		efficacyMapper.update(daoEntity);
	}
	
	/**
	 * @param entity
	 */
	public void delete(EfficacyEntity entity) {
		EfficacyDictEntity daoEntity = new EfficacyDictEntity(entity.getId(), entity.getName(), entity.getDesc(), (short) 1);
		efficacyMapper.delete(daoEntity);
	}

}
